package com.ark.service.service.impl;

import com.ark.common.domain.entity.game.GameDevice;
import com.ark.service.mapper.GameDeviceMapper;
import com.ark.service.service.GameDeviceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class GameDeviceServiceImpl extends ServiceImpl<GameDeviceMapper, GameDevice> implements GameDeviceService {

    private final static Logger log = LoggerFactory.getLogger(GameDeviceServiceImpl.class);

    @Resource
    private GameDeviceMapper gameDeviceMapper;

    @Override
    public boolean isDeviceExist(String deviceId) {
        return lambdaQuery().eq(GameDevice::getDeviceId, deviceId).exists();
    }

    @Override
    public GameDevice getDeviceByDeviceId(String deviceId) {
        return lambdaQuery().eq(GameDevice::getDeviceId, deviceId).one();
    }

    @Override
    public boolean updateDevice(GameDevice gameDevice) {
        return lambdaUpdate().eq(GameDevice::getId, gameDevice.getId()).update(gameDevice);
    }

    @Override
    public boolean insertDevice(GameDevice gameDevice) {

        return save(gameDevice);
    }

    @Override
    public List<GameDevice> getDeviceList(GameDevice gameDevice) {
        LambdaQueryWrapper<GameDevice> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GameDevice::getDelFlag, 0)
                .eq(Objects.nonNull(gameDevice.getStatus()), GameDevice::getStatus, gameDevice.getStatus())
                .like(Objects.nonNull(gameDevice.getDeviceName()), GameDevice::getDeviceName, gameDevice.getDeviceName());
        return list(wrapper);
    }

    @Override
    public boolean deleteDeviceByIds(Long[] deviceIds) {
        return gameDeviceMapper.deleteDeviceByIds(deviceIds) > 0;
    }
}
